<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">

		<link rel="stylesheet" href="/admin/plugins/layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="/admin/plugins/font-awesome/css/font-awesome.min.css">
	</head>

	<body>
		<!--<form class="layui-form">
			<div class="layui-form-item">
				<label class="layui-form-label">输入框</label>
				<div class="layui-input-block">
					<input type="text" name="" placeholder="请输入" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>-->
		<div style="margin: 15px;">
			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
				<!--<legend>响应式的表单集合</legend>-->
			</fieldset>
		
			<form class="layui-form" action="">
				<div class="layui-form-item">
					<label class="layui-form-label">数据库名称</label>
					<div class="layui-input-block">
						<input type="hidden" name="id" value="" />
						<input type="text" name="modelName" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">简要描述</label>
					<div class="layui-input-block">
						<textarea  name="modelDesc" class="layui-textarea"></textarea>
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">IP</label>
					<div class="layui-input-block">
						<input type="text" name="ip" lay-verify="ip" autocomplete="off" class="layui-input">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">SID</label>
					<div class="layui-input-block">
						<input type="text" name="sid" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">用户名</label>
					<div class="layui-input-block">
						<input type="text" name="user" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">密码</label>
					<div class="layui-input-inline">
						<input type="password" name="password" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				
				<!--<div class="layui-form-item">
					<label class="layui-form-label">是否启用</label>
					<div class="layui-input-block">
						<input type="checkbox" name="status" lay-skin="switch" title="是否启用" value="1">
					</div>
				</div>-->
				
				<!--被父级提交-->
				<div class="layui-form-item" style="display: none;">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit="" lay-filter="demo1" id="parentControlDom">立即提交</button>
						<!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
					</div>
				</div>
			</form>
		</div>
		<script type="text/javascript" src="/admin/plugins/layui/layui.js"></script>
		<script>
			layui.use(['form', 'layedit', 'laydate'], function() {
				var $ = layui.jquery,
					form = layui.form(),
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate;
		
				//创建一个编辑器
				//var editIndex = layedit.build('LAY_demo_editor');
				//自定义验证规则
				form.verify({
					ip:[/((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))/, 'IP地址格式不符']
				});
				
				window.loadGetDate = function(data){
					//console.log('form load data start.',data);
					if(data.success && data.data.length>0){
						var d = data.data[0];
						$("[name=id]").val(d.id);
						$("[name=ip]").val(d.ip);
						$("[name=modelDesc]").val(d.modelDesc);
						$("[name=modelName]").val(d.modelName);
						$("[name=password]").val(d.password);
						$("[name=sid]").val(d.sid);
						$("[name=user]").val(d.user);
					}
				}
				
				//监听提交
				form.on('submit(demo1)', function(data) {
					$.post(baseUrl+'/db_update', data.field, function(back){
						//console.log(back);
						if(back.success){
							layer.msg('保存成功');
							parent.window.reloadDbList();
						}else{
							layer.alert(back.error.code, {title:'警告',shade:0});
						}
					});
					return false;
				});
			});
		</script>
	</body>
</html>